/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import Action.TicketsCatSessionBeanLocal;
import Entity.TicketsCategory;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;

import javax.faces.bean.SessionScoped;


/**
 *
 * @author Cyrax
 */
@ManagedBean
@SessionScoped
public class TicketsCatBean {

    @EJB
    private TicketsCatSessionBeanLocal ticketsCatSessionBean;
    private TicketsCategory tkCat;
    private List<TicketsCategory> tcat;
    private TicketsCategory selectTk;

    /** Creates a new instance of TicketsCatBean */
    public TicketsCatBean() {
        tkCat = new TicketsCategory();
    }

    /**
     * @return the tkCat
     */
    public TicketsCategory getTkCat() {
        return tkCat;
    }

    /**
     * @param tkCat the tkCat to set
     */
    public void setTkCat(TicketsCategory tkCat) {
        this.tkCat = tkCat;
    }
    //list all

    public List<TicketsCategory> getListAllTicketsCat() {

        tcat = ticketsCatSessionBean.listAll();
        return tcat;

    }
    //add new

    public void insertTicketsCat() {
        try {

            if (tkCat.getTcName() == null) {
                System.out.println("Category is not null!!!");

            } else {
                ticketsCatSessionBean.addTicketsCat(tkCat);
            }

        } catch (Exception ex) {
            System.out.println("Error : " + ex.getMessage());
        }
    }

    //Update
    public void updateTicketsCat() {
    
//            InitialContext ctx = new InitialContext();
//
//            FacesContext context = FacesContext.getCurrentInstance();
//            Map map = context.getExternalContext().getRequestParameterMap();
            int tcID = selectTk.getTcID();
            System.out.println(tcID);
            ticketsCatSessionBean.ticketsCatUpdate(tcID, selectTk.getTcName(),selectTk.getPrice());
      
    }

    //Delete
    public void DeleteTicketsCat(TicketsCategory tkCat) {
        try {

            ticketsCatSessionBean.DeleteTicketsCat(tkCat);
        } catch (Exception e) {
            System.out.println("Error : " + e.getMessage());
        }
    }

    /**
     * @return the selectTk
     */
    public TicketsCategory getSelectTk() {
        return selectTk;
    }

    /**
     * @param selectTk the selectTk to set
     */
    public void setSelectTk(TicketsCategory selectTk) {
        this.selectTk = selectTk;
    }

     private String msCat;

    public void checkTicketsName() {
        if (ticketsCatSessionBean.checkTicketsCat(tkCat.getTcName())) {
            setMsCat("This Event Title is already existed");
        } else {
            setMsCat("");

        }
    }

    /**
     * @return the msCat
     */
    public String getMsCat() {
        return msCat;
    }

    /**
     * @param msCat the msCat to set
     */
    public void setMsCat(String msCat) {
        this.msCat = msCat;
    }
}
